/**
 *@brief define dev state resource
 *@date 2019-10-10
 *@author LY
 */
/*
 *通过对opendrive的xml文件,得到里面每条道路中每条几何元素(或者几何元素的部分)的数据
 *目前包括line、spiral、arc几何元素的数据(spiral的不明确,因为初始时形状变化不明显且螺旋线的长度较小,基准线用直线代替(误差不明显),车道线用起点切角和终点切角表示(误差不明显),但是spiral为道路最后几何元素时,不进行绘制)
 *包括通过车道线ID进行±校正的符号函数
 *包括QVector的合并和反转
 *（画笔，填充）
 */
#ifndef ROADDATA_H
#define ROADDATA_H

#include <QMainWindow>
#include <QPointF>
#include <QVector>
#include <QMap>
#include "lane.h"

#define __RODADATA (RoadData::getInstance())

struct PointInformation  //数据点信息
{
    QPointF point;  //数据点坐标
    double dHdg;  //数据点切角
};

class RoadData
{
private:
    RoadData();
    RoadData(RoadData &)
    {
    }

    RoadData &operator =(const RoadData&)
    {
        return *this;
    }

    ~RoadData();

public:
    static RoadData *getInstance()
    {
        static RoadData roadDataInstance;
        return &roadDataInstance;
    }

    //直线类型几何元素数据
    void getGeometryLineData(double sOffset, double dstartds, double dendds, double dstepSize, Geometry &geometry, LaneOffset &laneOffset, Lane &lane, QVector<QVector<QPointF>> &lanePoint);

    //螺旋线类型几何元素数据
    QVector<QPointF> getGeometrySpiralData(double xStart, double yStart, double hdgStart, double xEnd, double yEnd, double hdgEnd, double dWidth, double dLaneId);
    QVector<QPointF> getGeometrySpiralData(double xStart, double yStart, double xEnd, double yEnd);

    QVector<QPointF> getGeometryNewSpiralData(double x, double y, double dhdg, double dcurvStart, double dcurvEnd, double dlength, double dwidth, double dlaneId);

    //弧线类型几何元素数据
    void getGeometryArcData(double sOffset, double dstartds, double dendds, double dstepSize, Geometry &geometry, LaneOffset &laneOffset, Lane &lane, QVector<QVector<QPointF>> &lanePoint);

    //三次多项式几何元素数据
    void getGeometryPoly3Data(double sOffset, double dstartds, double dendds, double dstepSize, Geometry &geometry, Lane &lane, QVector<QVector<QPointF>> &lanePoint);

    //符号函数
    double sgn(double dSgnVar);

    template<typename T>
    bool isZero(T value);

    //数据类型QVector<QPointF>的合并,将客体object合并到主体main_body中
    void mergeQVectorQPointF(QVector<QPointF> &qvecDesPoint, const QVector<QPointF> &qvecSrcPoint);

    //对车道线进行车道填充数据
    QVector<QPointF> fillLaneData(const QVector<QPointF> &qvecOutsideLaneData, const QVector<QPointF> &qvecInsideLaneData);

    //通过map的key寻找对应的value
    int key2Value(const QString &strK);

    //y坐标取相反数
    void setYOppositeNumber(QVector<QPointF> &qvecData);
    QPolygonF getYOppositeNumber(const QPolygonF &polygon);
    QColor getColor(QString qstrType);
    Qt::PenStyle getPenStyle(QString qstrType);

private:
    enum Color
    {
        color0 = 0,
        color1,
        black,
        white,
        darkGray,
        gray,
        lightGray,
        red,
        green,
        blue,
        cyan,
        magenta,
        yellow,
        darkRed,
        darkGreen,
        darkBlue,
        darkCyan,
        darkMagenta,
        darkYellow,
        transparent,
//        NoPen = 0,
        SolidLine = 1,
        DashLine,
        DotLine,
        DashDotLine,
        DashDotDotLine,
        CustomDashLine
    };

    QMap<QString, int> m_qmapColorLineStyle;
    QMap<QString, QColor> m_qmapColor;
    QMap<QString, Qt::PenStyle> m_qmapPenStyle;
};

#endif // ROADDATA_H
